package com.faner.fast.upms.event;

import com.faner.fast.upms.model.SysLogDO;
import com.faner.fast.upms.service.SysLogService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.event.EventListener;
import org.springframework.core.annotation.Order;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

/**
 * 异步监听日志事件
 * @作者 faner
 * @创建时间 2021/1/25 12:56
 */
@Slf4j
@Component
@RequiredArgsConstructor
public class SysLogListener  {

    private final SysLogService sysLogService;

    @Async
    @Order
    @EventListener(SysLogEvent.class)
    public void saveSysLog(SysLogEvent event) {
        SysLogDO sysLog = (SysLogDO) event.getSource();
        sysLogService.save(sysLog);
    }
}
